/**
 * @Author lilinjie
 * @Description: 商品API
 */

import http from '@/utils/request'

// 获得商品
export const getAllProducts = ({ current: pageNum, pageSize }) => http({
  method: 'GET',
  url: `/admin/product/getProductList/${pageNum}/${pageSize}`
})

// 更新一个商品
export const updateProduct = data => http({
  method: 'PUT',
  url: `/admin/product/updateById`,
  data
})

// 根据品牌id获得商品
export const getProductByBrandId = ({ brandId }) => http({
  method: 'GET',
  url: `/admin/product/getProductByBrandId/${brandId}`
})

// 更新商品的审核状态
export const updateProductAuditStatus = ({ id, auditStatus }) => http({
  method: 'POST',
  url: `/admin/product/updateAuditStatus/${id}/${auditStatus}`
})

// 更新商品的上架状态
export const updateProductOnSaleStatus = ({ id, status }) => http({
  method: 'GET',
  url: `/admin/product/updateStatus/${id}/${status}`
})

// 根据商品id查找商品
export const getProductById = ({ brandId }) => http({
  method: 'GET',
  url: `/admin/product/getProductByBrandId/${brandId}`
})

// 删除一个商品
export const deleteProduct = (id) => http({
  method: 'DELETE',
  url: `/admin/product/deleteById/${id}`
})

// 插入一个商品
export const insertProduct = (data) => http({
  method: 'POST',
  url: `/admin/product/insertProduct`,
  data
})

// 根据条件查询商品
export const getProductByCondition = ({
  status,
  auditStatus,
  name,
  category1Id,
  brandId, current: pageNum, pageSize
}) => http({
  method: 'POST',
  url: `/admin/product/getProductListByQueryParam`,
  params: {
    pageNum,
    pageSize
  },
  data: {
    status,
    auditStatus,
    name,
    category1Id,
    brandId
  }
})
